#ifndef __IJPEGE_CLI_H__
#define __IJPEGE_CLI_H__

#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdbool.h>

#include <ijpege.h>

typedef void *hnd_t;

typedef struct cli_input_t cli_input_t;

typedef struct {
	FILE		*input_file;
	FILE		*output_file;
	int			i_csp;
	hnd_t		*hin;
	int			image_width;
	int			image_height;
	int			start_frame;
	int			sum_frames;
	cli_input_t *cli_input;
	char		*output_file_name;
    int         i_ql;

	/* buf managememt */
	/* must be vitural addr */
	bool b_use_phy;
	void *(*ckmalloc)(int index, int size, int align);
	void (*ckfree)(int index, void *);
	intptr_t (*ckvirt_to_phys)(intptr_t vaddr);
	intptr_t (*ckphys_to_virt)(intptr_t paddr);
} cli_opt_t;

struct cli_input_t
{
    int (*open_file)(char *filename, cli_opt_t *opt);
    int (*picture_alloc)(ijpege_pic_t *pic, cli_opt_t *opt);
    int (*read_frame)(ijpege_pic_t *pic, cli_opt_t *opt);
    int (*release_frame)(ijpege_pic_t *pic, cli_opt_t *opt);
    void (*picture_clean)(ijpege_pic_t *pic, cli_opt_t *opt);
    int (*close_file)(cli_opt_t *opt);
};

extern const cli_input_t cli_input_i420;
extern const cli_input_t cli_input_nv12;
extern const cli_input_t cli_input_t420;

static inline char *get_filename_extension(char *filename)
{
    char *ext = filename + strlen(filename);
    while( *ext != '.' && ext > filename )
        ext--;
    ext += *ext == '.';
    return ext;
}

#endif /* __IJPEGE_CLI_H__ */
